namespace OrganizationStructureTree.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.User",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Password = c.String(),
                        FirstName = c.String(),
                        LastName = c.String(),
                        MiddleName = c.String(),
                        Email = c.String(),
                        Phone = c.String(),
                        Company = c.String(),
                        Department = c.String(),
                        Project = c.String(),
                        Position = c.String(),
                        Manager = c.String(),
                        IsActivated = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.Nodes",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        ParentID = c.Int(),
                        TreeID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Tree", t => t.TreeID, cascadeDelete: true)
                .ForeignKey("dbo.Nodes", t => t.ParentID)
                .Index(t => t.TreeID)
                .Index(t => t.ParentID);
            
            CreateTable(
                "dbo.Tree",
                c => new
                    {
                        ID = c.Int(nullable: false, identity: true),
                        Name = c.String(),
                        CreatedOn = c.DateTimeOffset(nullable: false),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "dbo.UserNodes",
                c => new
                    {
                        ID = c.Int(nullable: false),
                        UserID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Nodes", t => t.ID)
                .ForeignKey("dbo.User", t => t.UserID, cascadeDelete: true)
                .Index(t => t.ID)
                .Index(t => t.UserID);
            
            CreateTable(
                "dbo.RootNodes",
                c => new
                    {
                        ID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Nodes", t => t.ID)
                .Index(t => t.ID);
            
            CreateTable(
                "dbo.DepartmentNodes",
                c => new
                    {
                        ID = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("dbo.Nodes", t => t.ID)
                .Index(t => t.ID);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.DepartmentNodes", new[] { "ID" });
            DropIndex("dbo.RootNodes", new[] { "ID" });
            DropIndex("dbo.UserNodes", new[] { "UserID" });
            DropIndex("dbo.UserNodes", new[] { "ID" });
            DropIndex("dbo.Nodes", new[] { "ParentID" });
            DropIndex("dbo.Nodes", new[] { "TreeID" });
            DropForeignKey("dbo.DepartmentNodes", "ID", "dbo.Nodes");
            DropForeignKey("dbo.RootNodes", "ID", "dbo.Nodes");
            DropForeignKey("dbo.UserNodes", "UserID", "dbo.User");
            DropForeignKey("dbo.UserNodes", "ID", "dbo.Nodes");
            DropForeignKey("dbo.Nodes", "ParentID", "dbo.Nodes");
            DropForeignKey("dbo.Nodes", "TreeID", "dbo.Tree");
            DropTable("dbo.DepartmentNodes");
            DropTable("dbo.RootNodes");
            DropTable("dbo.UserNodes");
            DropTable("dbo.Tree");
            DropTable("dbo.Nodes");
            DropTable("dbo.User");
        }
    }
}
